package com.mt.skyhoist.util.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.mt.skyhoist.R;
import com.mt.skyhoist.util.bean.DeviceModel;

public class DeviceChildView extends LinearLayout {
    private Context context;

    public DeviceChildView(Context context) {
        super(context);
        this.context = context;

        initView();
    }

    // 初始化控件
    private TextView devicename_txt;
    private ImageView rssi_imagview;

    private void initView() {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.fmt_device_child, this);

        devicename_txt = findViewById(R.id.devicename_txt);
        rssi_imagview = findViewById(R.id.rssi_imagview);

    }

    public void setData(DeviceModel device) {
        if(device == null) {
            devicename_txt.setText("");
            rssi_imagview.setBackground(null);
            return;
        }

        // 更新蓝牙基本参数
        devicename_txt.setText(device.getName());

        if(device.getRssi() == 0){   // 如果是0，则不要进行显示
            rssi_imagview.setImageBitmap(null);
            return;
        } else {
            rssi_imagview.setImageResource(R.drawable.wifi_orange);
            return;
        }
    }
}
